package org.feidao.chapter71;

import com.feidao.service.UserService;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.feidao.chapter71.service.UserServiceImpl;

//thrift server service的管理
public class UserServiceManager {
    //thrift service端口
    public final static int SERVER_USER_PORT = 8888;


    public UserServiceManager(){

    }

    public void server(){
        try {
            //创建TServer.Args
            TProcessor tProcessor = new UserService.Processor<UserService.Iface>(new UserServiceImpl());
            TServerSocket tServerSocket = new TServerSocket(SERVER_USER_PORT);
            TServer.Args args = new TServer.Args(tServerSocket);
            args.processor(tProcessor);
            args.protocolFactory(new TBinaryProtocol.Factory());

            //单线程服务模型,创建TServer
            TServer tServer = new TSimpleServer(args);

            //启动server
            tServer.serve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
